home *** CD-ROM | disk | FTP | other *** search
- Path: ip-salem3-09.teleport.com!user
- From: dynamix@teleport.com (Steve Budrys)
- Newsgroups: comp.lang.c++
- Subject: Re: Run time dynamic 2-D array?
- Date: Wed, 14 Feb 1996 17:13:52 -0800
- Organization: Dynamix Trading
- Message-ID: <dynamix-1402961713520001@ip-salem3-09.teleport.com>
- References: <4flcq9$i1k@vixen.cso.uiuc.edu>
- NNTP-Posting-Host: ip-salem3-09.teleport.com
-
- In article <4flcq9$i1k@vixen.cso.uiuc.edu>, WEIMIN YANG <w-yang3> wrote:
-
- > I need to use a 2-D array. I use following code.
- > void tryit(int a, int b) {
- >
- > float c= new float[b][a];
- >
- >
- > }
- > I get compile error. Is there another way to do it? By the way, I don't
- want to
- > use 1-D array to implement it.
-
- try
-
- float **MakeMatrix(int nRows, int nCols)
- {
- float **matrix = new float *[nRows];
- while(nRows--)
- matrix[nRows] = new float[nCols];
- return matrix;
- }
-
- (note that this gives you the effect of new float [a][b], not [b][a] )
-
- You'll also need to be able to tear it down:
-
- void DestroyMatrix(float **matrix, int nRows)
- {
- while(nRows--)
- delete [] matrix[nRows];
- delete [] matrix;
- }
-
- --
- Steve Budrys
- Dynamix Trading
-